package com.socialrss.viewlisteners;

import java.util.ArrayList;

import com.actionbarsherlock.app.SherlockFragment;
import com.socialrss.R;
import com.socialrss.adapters.SliderAdapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.Toast;

public class SlidingFragment extends SherlockFragment implements OnChildClickListener{

	ArrayList<String> groupItem = new ArrayList<String>();
	ArrayList<Object> childItem = new ArrayList<Object>();

	ExpandableListView exp;
	static Activity act;
	
	public SlidingFragment() {
		
	}
	
	public SlidingFragment(Activity act) {
		this.act = act;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.slider_content, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		exp = (ExpandableListView) getView().findViewById(
				R.id.slider_expandableListView);
		exp.setDividerHeight(2);
		exp.setGroupIndicator(null);
		exp.setClickable(true);
		setGroupData();
		setChildGroupData();
		SliderAdapter mNewAdapter = new SliderAdapter (groupItem, childItem);
		mNewAdapter.setInflater(
						(LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE),
						act);				//null pointer exception aliyo bekleyince
		// duzeltme kismi
		
		
		exp.setAdapter(mNewAdapter);
		exp.setOnChildClickListener(this);
	}

	public void setGroupData() {
		groupItem.add("Favorites");
		groupItem.add("General");
	}

	public void setChildGroupData() {
		/**
		 * Add Data For Favorites
		 */
		ArrayList<String> child = new ArrayList<String>();
		child.add("ACM");
		child.add("Bilkent");
		child.add("Singers");
		child.add("Politicians");
		child.add("Athletes");
		childItem.add(child);

		/**
		 * Add Data For General
		 */
		child = new ArrayList<String>();
		child.add("Manage Groups");
		child.add("Manage Connections");
		child.add("Manage Social Networks");
		child.add("Settings");
		child.add("Credits");
		childItem.add(child);
	}

	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		Toast.makeText(act, "Clicked On Child", Toast.LENGTH_SHORT).show();
		Intent intent = new Intent(act, OuterCategoryViewController.class);
		startActivity(intent);
		return true;
	}

}